#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================

import os
import numpy as np
import torch
import torch.nn.functional as F

def gen_golden_data_simple():
    dtype = np.float32
    input_shape = [8, 2048]

    input_p   = np.random.uniform(0.01, 0.99, input_shape).astype(dtype)
    input_y   = np.random.randint(0, 2, input_shape).astype(dtype)
    input_grad = np.random.uniform(-1.0, 1.0, input_shape).astype(dtype)
    input_weight = np.random.uniform(0.5, 2.0, input_shape).astype(dtype)

    p_torch   = torch.from_numpy(input_p)
    y_torch   = torch.from_numpy(input_y)
    grad_torch = torch.from_numpy(input_grad)
    weight_torch = torch.from_numpy(input_weight)

    golden = (grad_torch * (p_torch - y_torch) * weight_torch).numpy().astype(dtype)

    os.makedirs("input",  exist_ok=True)
    os.makedirs("output", exist_ok=True)

    input_p.tofile("./input/input_p.bin")
    input_y.tofile("./input/input_y.bin")
    input_grad.tofile("./input/input_grad.bin")
    input_weight.tofile("./input/weight.bin")  
    golden.tofile("./output/golden.bin")

if __name__ == "__main__":
    gen_golden_data_simple()
